//
//  InsetBorderButton.swift
//  Box
//
//  Created by mn on 2025/3/31.
//

import UIKit

class InsetBorderButton: UIButton{
    
    var inset: CGFloat = 3
    var borderWidth: CGFloat = 1
    var borderColor: UIColor = UIColor.black
    
    override func layoutSubviews() {
        super.layoutSubviews()
        addInsetBorder()
    }

    func addInsetBorder() {
        
        let borderLayer = CAShapeLayer()
        let path = UIBezierPath(roundedRect: bounds.insetBy(dx: inset, dy: inset), cornerRadius: 7.5)
        borderLayer.path = path.cgPath
        borderLayer.lineWidth = borderWidth
        borderLayer.strokeColor = borderColor.cgColor
        borderLayer.fillColor = UIColor.clear.cgColor
        
        layer.sublayers?.removeAll { $0 is CAShapeLayer }
        layer.addSublayer(borderLayer)
    }
}
